import _data_collection as dc
import _data_save as ds
import data_funcs as df
import _stock_selection as ss
import pandas as pd
import _params
import tushare as ts
import numpy
import datetime

#data = dc.collect_stock_list_by_sina()
#data = dc.collect_stock_list_by_tl('A')
#ds.save_stock_list_to_file_simple(data)
#ds.save_stock_list_to_file_addition(data, 'code')
#ds.save_stock_list_to_file_addition(data, 'ticker')

#stock_list = pd.read_csv('stock_list.csv', encoding=_params.__CSV_DECODE)
#print(stock_list)

#data = dc.collect_stock_day_by_tl(ticker='000002', beginDate='20160101')
#print(data)

#df.data_stock_list()
#df.data_stock_hq(['600030', '000001'])

#stock_hq_all= pd.read_excel("fama.xlsx")

# 根据日期进行分组，并取出每个周期的前N小值数据（市值*PB）
#stock_hq_all['fama'] = stock_hq_all['marketValue'] * stock_hq_all['PB']
#stock_hq_all = stock_hq_all.sort_values(by=['tradeDate', 'fama'])
#stock_hq_all = stock_hq_all.groupby(by='tradeDate').head(10)
#stock_hq_all.to_excel('test.xlsx')

#stock_bs = pd.read_excel('fama_result.xlsx', converters={'ticker':str}, parse_dates=['tradeDate'])
#stock_bs = stock_bs.groupby('tradeDate').sum()
#stock_bs['profitSum'] = (stock_bs['nextProfit'] + 1).cumprod() * 100
#print(stock_bs)

#date = dc.collect_newest_tradedate('20160320')
#date = '20160322'
#list = ss.fama_with_pb_mv(100,date)
#list.to_excel("list_" + date + ".xlsx", index=False)

list = ss.kdj_for_buy_signal(9,3,3,False)
list.to_excel("analysis/kdj/golden.xlsx")